
import javax.net.ssl.*;
import java.io.*;
 // java  -Djavax.net.ssl.trustStore SSLClient localhost 9090 .\TESTKEYSTRORE ali123
public class SSLClient {	

    public static void main(String[] arstring) 
	{
        try 
		{			
			if ((arstring.length >= 1) &&
				(arstring[0].equalsIgnoreCase("Help"))
			)
			{
			    System.out.println(" -Djavax.net.ssl.trustStore <UserID> <UserPassword> <Server IP > <Serverport> <KeyStore> <KeyStorePass>");
				return;
			}
			String strServer = "localhost";
			String strPort = "9090";	
			String strKeyStore ="TESTKEYSTRORE";			
			String strKeyStorePass ="ali123";			
			String strUser = "TEST";
			String strUserPass = "TESTPASS";
			
			if (arstring.length >= 1)
			{
				strUser = arstring[0];
			}
			if (arstring.length >=2)
			{
				strUserPass = arstring[1];
			}
			if (arstring.length >= 3)
			{
				strServer = arstring[2];
			}
			if (arstring.length >=4)
			{
				strPort = arstring[3];
			}			
			if (arstring.length >= 5)
			{				
				strKeyStore = arstring[4];
			}			
			if (arstring.length >= 6)
			{				
				strKeyStorePass = arstring[5];
			}
			
			System.setProperty( "javax.net.ssl.trustStore", strKeyStore);
			System.setProperty( "javax.net.ssl.trustStorePassword", strKeyStorePass );
			
			int iPort = Integer.parseInt(strPort);
			
			SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
            SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket(strServer, iPort);

            OutputStream outputstream = sslsocket.getOutputStream();
            OutputStreamWriter outputstreamwriter = new OutputStreamWriter(outputstream);
            BufferedWriter bufferedwriter = new BufferedWriter(outputstreamwriter);

		
            String string = "UserID:" + strUser + ",Password:" + strUserPass;
            bufferedwriter.write(string);
            bufferedwriter.flush();

            InputStream inputstream = sslsocket.getInputStream();
            InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
            BufferedReader bufferedreader = new BufferedReader(inputstreamreader);

            while ((string = bufferedreader.readLine()) != null)
            {
                System.out.println(string);
                System.out.flush();
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}

